package com.maya.controller;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.maya.model.User;
import com.maya.service.UserService;



@Controller

public class ViewUserFollowersController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/viewuserfollowers")
    public String viewUserfollowers(String viewedid,Model model) {
        
    	
        User viewedUser = userService.get(new ObjectId(viewedid));
        List<ObjectId> followerIds = viewedUser.getFollowerIds();
        List<User> followers = new ArrayList<User>();

        for(ObjectId id: followerIds) {
            User u = userService.get(id);
            followers.add(u);
        }
        System.out.println(followers.size() + "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        model.addAttribute("followers", followers);
        model.addAttribute("vieweduser", viewedUser);
        
        return "user-followers";
        
    }
}
